/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wasolicitudesfiec.AperturaPostgrado;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.rave.web.ui.component.Label;
import com.sun.rave.web.ui.component.StaticText;
import entidad.apertura.Solicitudaperturapostgrado;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlInputTextarea;
import wasolicitudesfiec.ApplicationBean1;
import wasolicitudesfiec.SessionBean1;
import wasolicitudesfiec.RequestBean1;
import wasolicitudesfiec.logicacontrol.Logica;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version Resolucion.java
 * @version Created on Jan 8, 2009, 2:27:28 PM
 * @author kabad
 */
public class Resolucion extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private StaticText staticText1 = new StaticText();

    public StaticText getStaticText1() {
        return staticText1;
    }

    public void setStaticText1(StaticText st) {
        this.staticText1 = st;
    }
    private Label lblTipo = new Label();

    public Label getLblTipo() {
        return lblTipo;
    }

    public void setLblTipo(Label l) {
        this.lblTipo = l;
    }
    private Label lblTema = new Label();

    public Label getLblTema() {
        return lblTema;
    }

    public void setLblTema(Label l) {
        this.lblTema = l;
    }
    private Label lblTipoApertura = new Label();

    public Label getLblTipoApertura() {
        return lblTipoApertura;
    }

    public void setLblTipoApertura(Label l) {
        this.lblTipoApertura = l;
    }
    private Label lblNumResolucion = new Label();

    public Label getLblNumResolucion() {
        return lblNumResolucion;
    }

    public void setLblNumResolucion(Label l) {
        this.lblNumResolucion = l;
    }
    private Label lblTemaApertura = new Label();

    public Label getLblTemaApertura() {
        return lblTemaApertura;
    }

    public void setLblTemaApertura(Label l) {
        this.lblTemaApertura = l;
    }
    private Label lblSolicitante = new Label();

    public Label getLblSolicitante() {
        return lblSolicitante;
    }

    public void setLblSolicitante(Label l) {
        this.lblSolicitante = l;
    }
    private Label lblEvaluador1 = new Label();

    public Label getLblEvaluador1() {
        return lblEvaluador1;
    }

    public void setLblEvaluador1(Label l) {
        this.lblEvaluador1 = l;
    }
    private Label lblEvaluador2 = new Label();

    public Label getLblEvaluador2() {
        return lblEvaluador2;
    }

    public void setLblEvaluador2(Label l) {
        this.lblEvaluador2 = l;
    }
    private Label lblEvaluador3 = new Label();

    public Label getLblEvaluador3() {
        return lblEvaluador3;
    }

    public void setLblEvaluador3(Label l) {
        this.lblEvaluador3 = l;
    }
    private Label lblResultadoResolucion = new Label();

    public Label getLblResultadoResolucion() {
        return lblResultadoResolucion;
    }

    public void setLblResultadoResolucion(Label l) {
        this.lblResultadoResolucion = l;
    }

    // </editor-fold>
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public Resolucion() {
    }
    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    private String texto;
    private String recomendaciones;

    @Override
    public void init() {
        FacesMessage message;

        super.init();
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("Resolucion Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
        }
        // </editor-fold>
        try {
            Logica logica = new Logica();
            int idSolicitud = Integer.parseInt(this.getExternalContext().getRequestParameterMap().get("idSolicitud"));
            Solicitudaperturapostgrado solicitud = logica.getLogAperturaPostgrado().leerSolicitudAperturaNivel2(idSolicitud);
            this.getLblTipo().setText(solicitud.getTipo().toUpperCase());
            this.getLblTema().setText(" \"" + solicitud.getTema().toUpperCase() + "\" ");

            if (solicitud.getResultadoResolucion().equals("Aprobada")) {
                if (solicitud.getTipo().equals("Maestría")) {
                    this.getLblResultadoResolucion().setText("APROBAR LA APERTURA DE LA ");
                } else {
                    this.getLblResultadoResolucion().setText("APROBAR LA APERTURA DEL ");
                }
            } else {
                this.getLblResultadoResolucion().setText("NO APROBAR LA APERTURA DEL ");
            }


            this.getLblTipoApertura().setText(solicitud.getTipo().toUpperCase());
            this.getLblTemaApertura().setText(" \"" + solicitud.getTema().toUpperCase() + " \"");
            if (solicitud.getProfesor() != null) {
                this.getLblSolicitante().setText(solicitud.getProfesor().getPersona().toString().toUpperCase());
                
            }
            this.getLblNumResolucion().setText(solicitud.getResolucion());
            if (solicitud.getEvaluador1() != null) {
                this.getLblEvaluador1().setText(solicitud.getEvaluador1().getPersona().toString().toUpperCase());
            }
            if (solicitud.getEvaluador2() != null) {
                this.getLblEvaluador2().setText(solicitud.getEvaluador2().getPersona().toString().toUpperCase());
            }
            if (solicitud.getEvaluador3() != null) {
                this.getLblEvaluador3().setText(solicitud.getEvaluador3().getPersona().toString().toUpperCase());                
            }
            if((solicitud.getEvaluador1() == null) && (solicitud.getEvaluador2() == null) && (solicitud.getEvaluador3() == null))
            {
            this.getLblEvaluador1().setText("(No se asignaron evluadores para esta solicitud)");
            }
            this.setRecomendaciones(solicitud.getComentarioResolucion());
        } catch (Exception ex) {
            message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Ocurrió un error no esperado, comuníquese con el administrador del sistema", ex.getLocalizedMessage());
            getFacesContext().addMessage(null, message);
            Logger.getLogger(Resolucion.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * @return the texto
     */
    public String getTexto() {
        return "hoslfdlhglh \n sferghtrjt\n sgffhgj";
    }

    /**
     * @param texto the texto to set
     */
    public void setTexto(String texto) {
        this.texto = texto;
    }

    /**
     * @return the recomendaciones
     */
    public String getRecomendaciones() {
        return recomendaciones;
    }

    /**
     * @param recomendaciones the recomendaciones to set
     */
    public void setRecomendaciones(String recomendaciones) {
       recomendaciones= recomendaciones.replaceAll("\n", "<br/>");
        this.recomendaciones = recomendaciones;
    }
}

